(setq ring-bell-function 'ignore)            ; 关闭响铃提示
(setq confirm-kill-emacs #'y-or-n-p)      ; 在关闭 Emacs 前询问是否确认关闭，防止误触
(global-auto-revert-mode t)                  ; 当另一程序修改了文件时，让 Emacs 及时刷新 Buffer
(delete-selection-mode t)                    ; 选中文本后输入文本会替换文本（更符合我们习惯了的其它编辑器的逻辑）
(setq inhibit-startup-message t)             ; 关闭启动 Emacs 时的欢迎界面
(setq make-backup-files nil)                 ; 关闭文件自动备份
;(add-hook 'prog-mode-hook #'hs-minor-mode)   ; 编程模式下，可以折叠代码块
(global-display-line-numbers-mode 1)         ; 在 Window 显示行号
(tool-bar-mode 0)                           ; （熟练后可选）关闭 Tool bar
(menu-bar-mode 0)
(when (display-graphic-p) (toggle-scroll-bar 0)) ; 图形界面时关闭滚动条
(setq-default tab-width 2)                   ; 设置tab宽度为2
(setq-default standard-indent 2)             ; 设置缩进宽度为2
(add-to-list 'default-frame-alist '(height . 35))
(add-to-list 'default-frame-alist '(width . 120))
(add-to-list 'default-frame-alist `(font . "FiraCode Nerd Font Mono"))
(scroll-bar-mode 0)
;; 设置默认编码为 UTF-8
;(set-language-environment 'UTF-8)
;(set-default-coding-systems 'utf-8)
;(set-terminal-coding-system 'utf-8)
;(set-keyboard-coding-system 'utf-8)
;(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;; 启动加速
;(global-font-lock-mode t)
(setq mouse-wheel-progressive-speed nil)
(setq dired-kill-when-opening-new-dired-buffer t)
(setq diff-hl-update-async t)

(defun execute-custom-command ()
  "Prompt user for a command and execute it in a shell."
  (interactive)
  (let ((command (read-from-minibuffer "Enter command: ")))
    (shell-command command)))

(global-set-key (kbd "C-c e") 'execute-custom-command)
(global-set-key (kbd "\C-c /") 'comment-or-uncomment-region)

(add-to-list 'load-path "~/.emacs.local") ;; .emacs.local is in https://github.com/rexim/dotfiles

(defun config-after-init()
  (setq file-name-handler-alist nil)
)
(add-hook 'after-init-hook #'config-after-init)

(defun config-after-prog-mode()
  (electric-pair-mode t)                       ; 自动补全括号
  (show-paren-mode t)
)
(add-hook 'prog-mode-hook #'config-after-prog-mode)

;; compilation-mode config
(setq compilation-scroll-output t)
(setq compilation-auto-jump-to-first-error t)
(setq compilation-max-output-line-length nil)
(add-hook 'compilation-filter-hook #'ansi-color-compilation-filter)

(provide 'init-config)
